package com.wyw.design.model.learning.behavioral.visitor;

import java.util.List;

/**
 * @Title   具体访问者——普通用户
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2023/4/19 17:18
 * Update History:
 * Author        Time            Content
 */
public class NormalVisitor implements Visitor {
    // 定义该用户具备的权限集合
    private List<String> lookPerms;
    NormalVisitor(List<String> lookPerms) {
        this.lookPerms = lookPerms;
    }
    @Override
    public void visit(FileElement fileElement) {
        if (this.lookPerms.indexOf(fileElement.getLookPerms()) >= 0) {
            System.out.println("当前：普通用户" + " 具备权限：" + this.lookPerms.toString() + " 要访问的文件名：" + fileElement.getName()  + " 允许访问!");
        } else {
            System.out.println("当前：普通用户" + " 具备权限：" + this.lookPerms.toString() +" 要访问的文件名：" + fileElement.getName() + " 权限不足，禁止访问!");
        }
    }
    @Override
    public void visit(DictionaryElement dictionaryElement) {
        if (this.lookPerms.indexOf(dictionaryElement.getLookPerms()) >= 0) {
            System.out.println("当前：普通用户" + " 具备权限：" + this.lookPerms.toString() + " 要访问的文件夹名：" + dictionaryElement.getName()  + " 允许访问!");
        } else {
            System.out.println("当前：普通用户" + " 具备权限：" + this.lookPerms.toString() +" 要访问的文件夹名：" + dictionaryElement.getName() + " 权限不足，禁止访问!");
        }
    }
}
